import json
import os

from pyecharts import options as opts
from pyecharts.charts import Page, Tree

def postOrderTraverseUpdate(node):
    data = {}
    data['name'] = str(format(node.simulate_quality,'.2f'))+'['+str(format(node.pi[0,0],'.2f'))+','+str(format(node.pi[0,1],'.2f'))+']'
    if node.children != []:
        data['children'] = []
        data['children'].append(postOrderTraverseUpdate(node.children[0]))
        data['children'].append(postOrderTraverseUpdate(node.children[1]))
    return data

def plotTree(rootnode, html):
    data = [postOrderTraverseUpdate(rootnode)]
    tree=(
         Tree()
            .add("", data,orient='TB',initial_tree_depth=-1)
            .set_global_opts(title_opts=opts.TitleOpts(title=html))
        )
    tree.render(html)